using System;
using System.Collections.Generic;
using System.Text;
using Castle.MicroKernel;
using Stormwind.Core.Data;

namespace Stormwind.Core.Configuration {
	/// <summary>
	/// Stormwind default dependency container.
	/// </summary>
	public class StormwindContainer {
		private DefaultKernel kernel;

		/// <summary>
		/// Default constructor.
		/// </summary>
		public StormwindContainer()
			: base() {
			kernel = new DefaultKernel();
			IConfiguration config = StormwindConfiguration.Current;
			Type tp = Type.GetType(config.DataBroker);
			if (tp == null) {
				throw new Faults.DataBrokerTypeNotFoundException(string.Format(ErrorMessages.DataBrokerNotFoundFaultMessage, config.DataBroker));
			}
			kernel.AddComponent("DataBroker", tp);
		}

		/// <summary>
		/// Configured Data broker.
		/// </summary>
		public IDataBroker DataBroker {
			get {
				return kernel.Resolve("DataBroker", new Dictionary<string,object>()) as IDataBroker;
			}
		}

		/// <summary>
		/// Stormwind Container instance.
		/// </summary>
		public static StormwindContainer Instance {
			get {
				return new StormwindContainer();
			}
		}
	}
}
